<?php

namespace App\Manage;


use App\Models\SiteInfo;
use App\Service\Base\Manage;

class SiteInfoManage extends Manage
{

    // 话题
    public function initialize()
    {
        parent::initialize();

        $this->model = 'SiteInfo';
    }

    // 父级
    // 添加，修改，删除，列表，停用 操作


    // 添加
    protected function _before_add()
    {
        $opt  = $this->option();
        $data = [
            'title'   => $opt->getData('title', null, 'trim'),
            'content' => $opt->getData('content', null, 'trim'),
            'status'  => $opt->getData('status', 1, 'intval'),
        ];

        // 文章内容处理
        if($data['content']){
            $data['content'] = htmlspecialchars_decode($data['content']);
            $data['content'] = str_replace("<br/>", "", $data['content']);
            //$data['content'] = str_replace("<p><br/></p>", "", $data['content']);
        }

        return $data;
    }

    // 修改
    protected function _before_edit()
    {
        $opt  = $this->option();
        $data = [
            'title'   => $opt->getData('title', null, 'trim'),
            'content' => $opt->getData('content', null, 'trim'),
            'status'  => $opt->getData('status', 1, 'intval'),
        ];

        // 文章内容处理
        if($data['content']){
            $data['content'] = htmlspecialchars_decode($data['content']);
            $data['content'] = str_replace("<br/>", "", $data['content']);
            //$data['content'] = str_replace("<p><br/></p>", "", $data['content']);
        }

        return $data;
    }

}


